<?php
    //接受商品id
    $goods_id = $_GET['id'];
    //查询该商品的封面图
    $sql = "
        select
        i.iname,g.gname,g.price,g.msg,g.zan,g.stock,g.sale
        from
        ".PRE."goods as g,".PRE."image as i
        where
        g.id = i.goods_id  and g.state = 1 and i.cover = 1 and g.id='$goods_id'  limit 1
        ";
    $goods_info = getRow($link, $sql);
    //查询该商品的其他图片
    $sql = "select iname from " .PRE ."image where goods_id = '$goods_id' and cover = 0";
    $goods_image_info = query($link, $sql);
    //第一次进入时,act为空,设置一个默认值
    if(empty($_GET['act'])){
        $_GET['act']='details';
    }

    //查询该商品的评价
    $sql = "select
            e.content,i.image_name
            from
            ".PRE."evaluate as e,".PRE."evaluate_image as i
            where
            e.id = i.evaluate_id and e.display = 1 and e.goods_id = '$goods_id'
            ";
    $evaluate_list = query($link, $sql);

    //查看该商品的评价的总条数
    $sql = "select count(*) as total from ".PRE."evaluate where goods_id = '$goods_id'";
    $total_evaluate = getRow($link, $sql);
    $total_evaluate = $total_evaluate['total'];

 ?>

<div class="container mt50">
    <div class="row mt50">
        <div class="col-md-4 pull-left">
                    <div class="thumbnail">
                        <img id="big" src="<?php echo get_img_url(ROOT_URL . './upload',$goods_info['iname'],0)?>">
                        <div class="row mt10">
                            <ul>
                                <li class="col-md-2">
                                    <img class="pic" onmousemove="changesrc(this)" src="<?php echo get_img_url(ROOT_URL . './upload',$goods_info['iname'],50)?>">
                                </li>
                                <?php if(!empty($goods_image_info)):?>
                                    <?php foreach($goods_image_info as $val):?>
                                        <li class="col-md-2">
                                            <img class="pic" onmousemove="changesrc(this)" src="<?php echo get_img_url(ROOT_URL . './upload',$val['iname'],50)?>">
                                        </li>
                                    <?php endforeach;?>
                                <?php endif;?>


                            </ul>
                        </div>
                    </div>
        </div><!--pull-left end-->

        <div class="col-md-7 pull-right">
            <!--商品名字和详细信息-->
            <div class="row">
                <h3><b><?php echo $goods_info['gname']?></b></h3>
                <p class="text-danger"><?php echo $goods_info['msg']?></p>
            </div>
            <!--商品价格-->
            <div class="row mt10">
                <h3 class="col-md-6 price">价格:&nbsp;&nbsp;
                    <span class="glyphicon glyphicon-jpy" style="color: #f78d03;"></span>
                    <span style="color: #f78d03;"><?php echo $goods_info['price']?></span>
                </h3>
                <h3 class="col-md-4">
                    <?php ?>
                    <span class="glyphicon glyphicon-heart text-danger"></span>
                    <span class="text-center"><?php echo $goods_info['zan']?></span>
                </h3>

            </div>
            <!--商品数量-->
            <form action="./com/buydo.php" method="post">
                <input type="hidden" name="goods_id" value="<?php echo $goods_id;?>">
                <input type="hidden" name="stock" value="<?php echo $goods_info['stock'];?>">
                <h3 class="col-md-2 price">数量:</h3>
                <h4 class="col-md-4 price">
                    <div class="col-md-3 btn btn-default" onclick="minus(<?php echo $goods_id;?>)">▬</div>
                    <div class="col-md-6">
                        <input type="number" name="qty" value="1" id="number<?php echo $goods_id;?>" class="form-control text-center">
                    </div>
                    <div class="col-md-3 btn btn-default" onclick="plus(<?php echo $goods_id;?>)">✚</div>
                </h4>
                <h3 class="col-md-3 price">库存:<?php echo $goods_info['stock']?></h3>
                <h3 class="col-md-3 price">销量:<?php echo $goods_info['sale']?></h3>
                <br>
                <h3 class="col-md-12 price">
                    <button class="btn btn-success" type="submit" name="act" value="buy">立即购买</button>
                    <button class="btn btn-danger" type="submit" name="act" value="add_cart">加入购入车</button>
                </h3>

            </form>

        </div><!--pull-right end-->
    </div><!--row end-->
    <div class="row mt50">
        <ul class="nav nav-tabs">
            <li role="presentation" class="active">
                <a href="<?php echo ROOT_URL?>goods_details.php?act=details&id=<?php echo $goods_id?>">
                    商品详情
                </a>
            </li>
            <li role="presentation">
                <a href="<?php echo ROOT_URL?>goods_details.php?act=user_evaluate&id=<?php echo $goods_id?>">
                    用户评价(<span class="text-danger"><?php echo $total_evaluate?></span>)
                </a>
            </li>
        </ul>
        <!-- 商品详情-->
        <?php if($_GET['act'] == 'details'):?>
            <ul>
                <li><img src="<?php echo get_img_url(ROOT_URL . './upload',$goods_info['iname'],0)?>"></li>
                <?php if(!empty($goods_image_info)):?>
                    <?php foreach($goods_image_info as $val):?>
                        <li>
                            <img class="pic" onmousemove="changesrc(this)" src="<?php echo get_img_url(ROOT_URL . './upload',$val['iname'],0)?>">
                        </li>
                    <?php endforeach;?>
                <?php endif;?>
            </ul>
        <?php endif;?>
        <!-- 用户评价-->
        <?php if($_GET['act'] == 'user_evaluate'):?>
            <?php if(!empty($evaluate_list)):?><!--如果有评论的话-->
                <?php foreach($evaluate_list as $value):?>
                    <br>匿名用户:<br>
                    <div class="media">

                        <?php if(!empty($value['image_name'])):?>
                            <div class="media-left">
                                <a href="#">
                                    <img class="media-object" src="<?php echo get_img_url(ROOT_URL.'upload_evaluate_image/',$value['image_name'],50)?>">
                                </a>
                            </div>
                        <?php endif;?>
                        <div class="media-body">
                            <?php echo $value['content']?>
                        </div>
                        <hr>
                    </div>




                <?php endforeach;?>
            <?php endif;?>

        <?php endif;?>


    </div>

</div><!--container end-->
